# sqlite3 -batch -separator ' ' trace.sqlite "select * from overheadHelp;" > overhead.txt
# awk -f overheadAnalysis.awk overhead.txt


BEGIN {
	dobjCurrent = 0;
}

{
	dobjId = $1;
	nodeId1 = $2;
	nodeId2 = $3;
	eventName = $4;
	time = $5;
	
	if (dobjId != dobjCurrent) {
		cntRelevant = 0;
		
		for (s=0;s<cntAccept;s++) {
			for (n=0;n<cntApp;n++) {
				if (aAccept[s] == aApp[n]) {
					cntRelevant++;
				}
			}
		}

		if (cntAccept > 0) {
			print "eval", dobjCurrent, cntAccept, cntRelevant, cntReject;
		}
	
		cntAcceptTotal += cntAccept;
		cntRejectTotal += cntReject;
		cntRelevantTotal += cntRelevant;

		delete aReject;
		delete aRejectTime;
		delete aAccept;
		delete aAcceptTime;
		delete aAcceptReject;
		delete aApp;
		cntReject = 0;
		cntAccept = 0;
		cntApp = 0;

		dobjCurrent = dobjId;
	}

	if (eventName == "INCOMING_REJECT") {
		aReject[cntReject] = nodeId1;
		aRejectTime[cntReject] = time;
		cntReject++;
	}
	if (eventName == "INCOMING_ACCEPT" && nodeId2!="3ced") {
		aAccept[cntAccept] = nodeId2;
		aAcceptTime[cntAccept] = time;
		aAcceptReject[cntAccept] = reject;
		cntAccept++;
	}
	if (eventName == "EVENT_TYPE_DATAOBJECT_SEND_SUCCESSFUL" && nodeId2=="appl") {
		aApp[cntApp] = nodeId1;
		cntApp++;
	}



}

END {
	print cntAcceptTotal, cntRelevantTotal, cntRejectTotal;
}